home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / laptop-mode-tools / modules / cpufreq < prev    next >
Encoding:
Text File  |  2012-05-20  |  4.6 KB  |  142 lines

  1. #! /bin/sh
  2. #
  3. # Laptop mode tools module to handle CPU frequency settings.
  4. #
  5.  
  6. # Set kernel setting, showing an error if this fails.
  7. # Parameter 1: sysctl/proc path
  8. # Parameter 2: the value
  9. set_sysctl() {
  10.     log "VERBOSE" "Executing: echo $2 > $1"
  11.     if ! echo "$2" > "$1" ; then
  12.         echo "SETTING OF KERNEL PARAMETER FAILED: echo $2 \> $1"
  13.     fi
  14. }
  15.  
  16.  
  17. #
  18. # get_medium_value
  19. #
  20. #   Get the medium value from a list of numerical values.
  21. #   $1 = file containing the list of values
  22. #
  23. get_medium_value() {
  24.     cat "$1" | tr ' ' '\n' | sort -n | awk -v RS="" '{n=split($0,a); print a[int((n+1)/2)]}'
  25. }
  26.  
  27.  
  28. if [ x$CONTROL_CPU_FREQUENCY = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_CPU_FREQUENCY = xauto ]; then
  29.     if [ $ON_AC -eq 1 ] ; then
  30.         if [ "$ACTIVATE" -eq 1 ] ; then
  31.             CPU_MAXFREQ="$LM_AC_CPU_MAXFREQ"
  32.             CPU_MINFREQ="$LM_AC_CPU_MINFREQ"
  33.             CPU_GOVERNOR="$LM_AC_CPU_GOVERNOR"
  34.             CPU_IGNORE_NICE_LOAD="$LM_AC_CPU_IGNORE_NICE_LOAD"
  35.         else
  36.             CPU_MAXFREQ="$NOLM_AC_CPU_MAXFREQ"
  37.             CPU_MINFREQ="$NOLM_AC_CPU_MINFREQ"
  38.             CPU_GOVERNOR="$NOLM_AC_CPU_GOVERNOR"
  39.             CPU_IGNORE_NICE_LOAD="$NOLM_AC_CPU_IGNORE_NICE_LOAD"
  40.         fi
  41.     else
  42.         CPU_MAXFREQ="$BATT_CPU_MAXFREQ"
  43.         CPU_MINFREQ="$BATT_CPU_MINFREQ"
  44.         CPU_GOVERNOR="$BATT_CPU_GOVERNOR"
  45.         CPU_IGNORE_NICE_LOAD="$BATT_CPU_IGNORE_NICE_LOAD"
  46.     fi
  47.     for THISCPU in /sys/devices/system/cpu/* ; do
  48.         if [ -e $THISCPU/cpufreq/cpuinfo_min_freq ]; then
  49.             THIS_CPU_MAXFREQ="$CPU_MAXFREQ"
  50.             THIS_CPU_MINFREQ="$CPU_MINFREQ"
  51.             THIS_CPU_GOVERNOR="$CPU_GOVERNOR"
  52.             THIS_CPU_IGNORE_NICE_LOAD="$CPU_IGNORE_NICE_LOAD"
  53.             
  54.             case "$CPU_MAXFREQ" in
  55.             "slowest")
  56.                 THIS_CPU_MAXFREQ=`cat $THISCPU/cpufreq/cpuinfo_min_freq`
  57.                 ;;
  58.             "medium")
  59.                 THIS_CPU_MAXFREQ=$(get_medium_value $THISCPU/cpufreq/scaling_available_frequencies)
  60.                 ;;
  61.             "fastest")
  62.                 THIS_CPU_MAXFREQ=`cat $THISCPU/cpufreq/cpuinfo_max_freq`
  63.                 ;;
  64.             esac
  65.             
  66.             case "$CPU_MINFREQ" in
  67.             "slowest")
  68.                 THIS_CPU_MINFREQ=`cat $THISCPU/cpufreq/cpuinfo_min_freq`
  69.                 ;;
  70.             "medium")
  71.                 THIS_CPU_MINFREQ=$(get_medium_value $THISCPU/cpufreq/scaling_available_frequencies)
  72.                 ;;
  73.             "fastest")
  74.                 THIS_CPU_MINFREQ=`cat $THISCPU/cpufreq/cpuinfo_max_freq`
  75.                 ;;
  76.             esac
  77.  
  78.             log "VERBOSE" "Setting CPU maximum frequency for cpu $THISCPU to $THIS_CPU_MAXFREQ."
  79.             set_sysctl $THISCPU/cpufreq/scaling_max_freq $THIS_CPU_MAXFREQ
  80.             log "VERBOSE" "Setting CPU minimum frequency for cpu $THISCPU to $THIS_CPU_MINFREQ."
  81.             set_sysctl $THISCPU/cpufreq/scaling_min_freq $THIS_CPU_MINFREQ
  82.             log "VERBOSE" "Setting CPU frequency governor for cpu $THISCPU to $THIS_CPU_GOVERNOR."
  83.             log "VERBOSE" "`/sbin/modprobe -q cpufreq_$THIS_CPU_GOVERNOR 2>&1`"
  84.             set_sysctl $THISCPU/cpufreq/scaling_governor $THIS_CPU_GOVERNOR
  85.  
  86.             # Retain for backward compatibility
  87.             if [ -f "$THISCPU/cpufreq/$THIS_CPU_GOVERNOR/ignore_nice_load" ] ; then
  88.                 log "VERBOSE" "Setting CPU ignore_nice_load for cpu $THISCPU to $THIS_CPU_IGNORE_NICE_LOAD."
  89.                 set_sysctl $THISCPU/cpufreq/$THIS_CPU_GOVERNOR/ignore_nice_load $THIS_CPU_IGNORE_NICE_LOAD
  90.             else
  91.                 log "VERBOSE" "Not setting CPU ignore_nice_load for cpu $THISCPU."
  92.                 log "VERBOSE" "File $THISCPU/cpufreq/$THIS_CPU_GOVERNOR/ignore_nice_load does not exist."
  93.             fi
  94.         fi
  95.     done
  96.  
  97.     # For kernels 2.6.32 and above, the sysfs interface for OnDemand per-core power savings has changed.
  98.     # Instead of per-core, the new interface is generic and a single one
  99.     if [ -f "/sys/devices/system/cpu/cpufreq/$THIS_CPU_GOVERNOR/ignore_nice_load" ]; then
  100.         log "VERBOSE" "Setting CPU ignore_nice_load for all cpus"
  101.         set_sysctl /sys/devices/system/cpu/cpufreq/$THIS_CPU_GOVERNOR/ignore_nice_load $CPU_IGNORE_NICE_LOAD
  102.     else
  103.         log "VERBOSE" "No generic CPU ignore_nice_load interface available"
  104.     fi
  105. fi
  106.  
  107. if [ x$CONTROL_CPU_THROTTLING = x1 ]  || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_CPU_THROTTLING = xauto ]; then
  108.     if [ $ON_AC -eq 1 ] ; then
  109.         if [ "$ACTIVATE" -eq 1 ] ; then
  110.             CPU_THROTTLING="$LM_AC_CPU_THROTTLING"
  111.         else
  112.             CPU_THROTTLING="$NOLM_AC_CPU_THROTTLING"
  113.         fi
  114.     else
  115.         CPU_THROTTLING="$BATT_CPU_THROTTLING"
  116.     fi
  117.     for THISCPU in /proc/acpi/processor/* ; do
  118.         if [ -e $THISCPU/throttling ]; then
  119.             NUM_LEVELS=`cat $THISCPU/throttling | grep "T[0123456789]*\:" | wc -l`
  120.             case "$CPU_THROTTLING" in
  121.             "minimum")
  122.                 THIS_CPU_THROTTLING=0
  123.                 ;;
  124.             "medium")
  125.                 # Divide but round up: that way, "medium" on a two-level system will
  126.                 # lead to full throttling -- which is 50% on my system, quite reasonable.
  127.                 THIS_CPU_THROTTLING=$(( ($NUM_LEVELS / 2 ) ))
  128.                 ;;
  129.             "maximum")
  130.                 THIS_CPU_THROTTLING=$(($NUM_LEVELS - 1))
  131.                 ;;
  132.             *)
  133.                 THIS_CPU_THROTTLING="$CPU_THROTTLING"
  134.             esac
  135.             
  136.             log "VERBOSE" "Setting throttling level for cpu $THISCPU to $THIS_CPU_THROTTLING."
  137.             set_sysctl $THISCPU/throttling $THIS_CPU_THROTTLING
  138.         fi
  139.     done
  140. fi
  141.  
  142.